package com.sharepics.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.sharepics.bean.Album;
import com.sharepics.bean.Picture;
import com.sharepics.dao.AlbumDAO;
import com.sharepics.dao.PictureDAO;

@Controller
public class PictureController {

	@Autowired
	PictureDAO pictureDAO;
	
	
	private List<Picture> pictures;
	
    @RequestMapping(value = "/picture/list",method = RequestMethod.GET)
    public  ModelAndView list(@RequestParam("albumId") Long albumId) {
    	ModelAndView mav = new ModelAndView();
    	List<Picture> pictures = pictureDAO.findByAlbum(albumId);
    	System.out.println("PIC : "+pictures);
    	mav.addObject("pictures", pictures);
    	mav.setViewName("picture/list");
    	return mav;
    }

    @ModelAttribute("pictures")
	public List<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
	}
    
    
}
